<template>
  <section class="component survey-records">
    <data-box :data="dataSet">
      <template slot="columns">
        <el-table-column prop="surveyResults" label="调查结果" :formatter="row => formatterResult(row)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="description" label="调查说明" show-overflow-tooltip></el-table-column>
        <el-table-column prop="operatorRealName" label="调查人"></el-table-column>
        <el-table-column prop="createTime" label="调查时间" :formatter="row  => $filter.dateFormat(row.createTime)"></el-table-column>
        <el-table-column prop="" label="附件">
          <template slot-scope="scope">
            <el-button type="text" @click="fileIds = scope.row.recordFiledIds,dialog.fileList = true">查看附件</el-button>
          </template>
        </el-table-column>
      </template>
    </data-box>
    <div class="operate-buttons">
      <el-button @click="emitClose">关闭</el-button>
    </div>

    <el-dialog title="附件信息" :center="true" :visible.sync="dialog.fileList" width="800px" append-to-body>
      <view-attach-list :fileIds="fileIds" @close="dialog.fileList = false"></view-attach-list>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Dependencies } from '~/core/decorator';
import { Emit, Prop, Watch } from 'vue-property-decorator';
import { State } from 'vuex-class';
import DataBox from "~/components/common/data-box.vue";
import { CaseAssistAntiFraudSurveyCaseService } from '~/services/domain-service/case-assist-anti-fraud-survey-case.service.ts';
import ViewAttachList from "~/components/common/view-attach-list.vue";

@Component({
  components: {
    DataBox,
    ViewAttachList
  },
})
export default class SurveyRecords extends Vue {
  @Prop({ required: true })
  private assistId: string
  @State private customDataDict: any[];
  @Dependencies(CaseAssistAntiFraudSurveyCaseService)
  private caseAssistAntiFraudSurveyCaseService: CaseAssistAntiFraudSurveyCaseService;

  private dataSet: any[] = [];
  private dialog = {
    fileList: false
  }
  private fileIds: string = ""

  @Emit('close')
  private emitClose() {}

  @Watch("assistId", { immediate: true })
  private onAssistIdChange(val) {
    this.dataSet = []
    if (val) {
      this.caseAssistAntiFraudSurveyCaseService.getCheatDetails(val).subscribe(data => this.dataSet = data)
    }
  }

  private formatterResult(row) {
    let result = this.$filter.dictConvert(row.surveyResults, 'SurveyResults')
    if (row.surveyResults === "Fraud") {
      const tmpResult1 = this.customDataDict.find(v => v.id === row.dataPoolId)
      if (tmpResult1) {
        const tmpResult2 = this.customDataDict.find(v => v.id === tmpResult1.parentId)
        if (tmpResult2) {
          result += `/${tmpResult2.name}/${tmpResult1.name}`
        } else {
          result += `/${tmpResult1.name}`
        }
      }
    }
    return result
  }


}
</script>

<style lang="less" scoped>
</style>
